<?php
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 xoops.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
// Author: Dirk Herrmann (Alfred)                                            //
// Site: http://www.simple-xoops.de                                          //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //

class blockcategorie extends XoopsObject {

  function blockcategorie() {
	  $this->XoopsObject();
	  $this->initVar('catid', XOBJ_DTYPE_INT, NULL, false);
	  $this->initVar('visible', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('title', XOBJ_DTYPE_TXTBOX, NULL, true, 255, true);
	  $this->getData();
  }

  function set($id) {
    if (is_array($id) && count($id) > 0) {
	    foreach ($id as $key => $value) {
		  $this->setVar($key,$value);
		}
	  }
  }
	
  function is_new() {
	 if ($this->getVar('catid') == 0) return true;
		return false;
  }
	
  function load($id) {
    global $xoopsDB,$xoopsModule;
	if (intval($id) > 0 ) {
      $sql   = "SELECT * FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." WHERE catid=".intval($id)."";
      $myrow = $xoopsDB->fetcharray($xoopsDB->query($sql));
      if ($myrow) $this->set($myrow);
	}
  }
	
  function getData() {
    global $_POST;
	if (isset($_POST)) {
	  $myts =& MyTextSanitizer::getInstance();
	  $rr=array();
	  $mm = (isset($_POST['title'])) ? $_POST['title'] : "";
	  $rr['title'] = $myts->stripSlashesGPC($mm);
	  $rr['visible'] = (isset($_POST['visible'])) ? intval($_POST['visible']) : 0;
	  $rr['catid'] = (isset($_POST['catid'])) ? intval($_POST['catid']) : 0;
	  $this->set($rr);
	  return true;
	}
	return false;
  }
	
  function getform_delete() {
	    global $xoopsModule,$xoopsDB;
	    $form = new XoopsThemeForm(_INFO_SETDELETE, $xoopsModule->getVar('dirname')."_form_delete", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	    $form->setExtra('enctype="multipart/form-data"');  
		$form->addElement(new XoopsFormHidden('catid', $this->getVar('catid')));	
		$form->addElement(new XoopsFormHidden('op', 'blockcat_delete'));
		$form->addElement(new XoopsFormLabel('', sprintf(_INFO_SETDELETE_FRAGE,$this->getVar('title'))));
		$sql="SELECT count(*) as count FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." WHERE homepage=".intval($this->getVar('catid'));
		$result=$xoopsDB->query($sql);
		$row=$xoopsDB->fetchrow($result);
		$count = ($result) ? intval($row[0]) : 0;
		$form->addElement(new XoopsFormLabel('', sprintf(_INFO_SETDELETE_LIST,$count)));
		$submit = new XoopsFormElementTray("", "");
	    $submit->addElement(new XoopsFormButton('', 'post', _YES, 'submit'));
		$submit->addElement(new XoopsFormButton('', 'post', _NO, 'submit'));
        $form->addElement($submit);
	    $form->display();
	}
	
	function getform_edit() {
	  global $xoopsModule,$xoopsModuleConfig;
	  $tueber = ($this->is_new()) ? _INFO_ADDBLOCKCAT : _INFO_EDITBLOCKCAT;
	  $form = new XoopsThemeForm($tueber, $xoopsModule->getVar('dirname')."_form_edit", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	    $form->setExtra('enctype="multipart/form-data"');  
	  $form->addElement(new XoopsFormHidden('catid', $this->getVar('catid')));	
	  $form->addElement(new XoopsFormHidden('op', 'blockcat_insert'));
	  $form->addElement(new XoopsFormText(_INFO_HOMEPAGE, "title", 80, 255,$this->getVar('title')),true); 
	  //$visible_checkbox = new XoopsFormCheckBox(_INFO_VISIBLE, 'visible',$this->getVar('visible'));
	  //$visible_checkbox->addOption(1, _YES);
	  //$form->addElement($visible_checkbox);
	  $submit = new XoopsFormButton('', 'post', $tueber, 'submit');
      $form->addElement($submit);
	  $form->display();
	}
	
	function getform_list() {
	    global $xoopsModule,$xoopsModuleConfig,$xoopsDB;
		$form = new XoopsThemeForm(_INFO_LISTBLOCKCAT, $xoopsModule->getVar('dirname')."_form_list", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	    $form->setExtra('enctype="multipart/form-data"');  
		$form->addElement(new XoopsFormHidden('op', 'blockcat_list'));
		$sql="SELECT catid,title FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." ORDER BY title ASC";
		$result=$xoopsDB->query($sql);
		$blist=array();
		if ($result) {
		  while($myrow = $xoopsDB->fetcharray($result)) {
			  $blist[$myrow['catid']] =  $myrow['title'];
			}
		} 
		$block_select = new XoopsFormSelect(_INFO_HOMEPAGE, "cat",$this->getVar('catid'));
		$block_select->addOptionArray($blist);
	    $form->addElement($block_select);
		$submit = new XoopsFormElementTray("", "");
	    $submit->addElement(new XoopsFormButton('', 'post', _DELETE, 'submit'));
		$submit->addElement(new XoopsFormButton('', 'post', _EDIT, 'submit'));
        $form->addElement($submit);
		$form->display();
	}
	
	function insert() {
	  global $xoopsDB,$xoopsModule;
	  if (trim($this->getVar('title')) == "") {
		   $this->setErrors(_INFO_ERROR_NOBLOCKTITLE);
	  } else {
		  if ($this->is_new()) {
		    $sql="SELECT count(*) as count from ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." WHERE title ='".$this->getVar('title')."'";
			$result=$xoopsDB->query($sql);
			if ($result) {
			  $myrow = $xoopsDB->fetchrow($result);
			  if ($myrow[0] > 0) $this->setErrors(_INFO_ERROR_ISSETBLOCKTITLE);
			} 
			if (count($this->getErrors()) == 0) {
				$sql="INSERT INTO ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." (title) VALUES ('".$this->getVar('title')."')";
				$result=$xoopsDB->query($sql);
				if (!$result) $this->setErrors(_INFO_ERROR_NOINSERTDB);
			}
		  } else {
		    $sql="UPDATE ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." SET title='".$this->getVar('title')."' WHERE catid=".intval($this->getVar('catid'));
			$result=$xoopsDB->query($sql);
			if (!$result) $this->setErrors(_INFO_ERROR_NOINSERTDB);
		  }
		}
	  return (count($this->getErrors()));
	}
}

class infosite extends XoopsObject {

  function infosite() {
	  $this->XoopsObject();
	  $this->initVar('storyid', XOBJ_DTYPE_INT, NULL, false);
	  $this->initVar('bakid', XOBJ_DTYPE_INT, NULL, false);
	  $this->initVar('owner', XOBJ_DTYPE_INT, -1, false);
	  $this->initVar('st', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('frontpage', XOBJ_DTYPE_INT, 0, false);
	  $fr=array('height'=>'250','border'=>'0','width'=>'100','align'=>'center');
	  $this->initVar('frame', XOBJ_DTYPE_OTHER, serialize($fr), true);
	  $this->initVar('click', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('self', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('parent_id', XOBJ_DTYPE_INT, NULL, false);
	  $this->initVar('blockid', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('title', XOBJ_DTYPE_TXTBOX, NULL, true, 255, true);
	  $this->initVar('text', XOBJ_DTYPE_TXTAREA, NULL, true, NULL, true);
	  $this->initVar('visible', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('nobreaks', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('nocomments', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('homepage', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('submenu', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('link', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('address', XOBJ_DTYPE_TXTBOX, NULL, true, 255, true);
	  $this->initVar('visible_group', XOBJ_DTYPE_OTHER, '1,2,3', true);
	  $this->initVar('edited_time', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('edited_user', XOBJ_DTYPE_INT, 0, false);
	  $this->initVar('title_sicht', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('footer_sicht', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('tooltip', XOBJ_DTYPE_TXTBOX, NULL, false, 255, true);
	  $this->initVar('bl_left', XOBJ_DTYPE_INT, 1, false);
	  $this->initVar('bl_right', XOBJ_DTYPE_INT, 1, false);
	  $this->getData();
  }
	
	function set($id) {
    if (is_array($id) && count($id) > 0) {
		  foreach ($id as $key => $value) {
			  $this->setVar($key,$value);
		  }
	  }
  }
	
	function load($id) {
    global $xoopsDB,$xoopsModule;
	if (intval($id) >0 ) {
      $sql   = "SELECT * FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." WHERE storyid=".intval($id)."";
	  $myrow = $xoopsDB->fetcharray($xoopsDB->query($sql));
	  if ($myrow) {
		$myrow['dohtml'] = $myrow['nohtml'];
		$myrow['dobr'] = $myrow['nobreaks'];
		unset($myrow['nohtml']);
		unset($myrow['nobreaks']);
		$this->set($myrow);
	  }
	}
  }
	
  function load_app($id) {
    global $xoopsDB,$xoopsModule;
	if (intval($id) >0 ) {
      $sql = "SELECT * FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))."_bak WHERE bakid=".intval($id)."";
	  $myrow = $xoopsDB->fetcharray($xoopsDB->query($sql));
	  if ($myrow) {
		$myrow['dohtml'] = $myrow['nohtml'];
		$myrow['dobr'] = $myrow['nobreaks'];
		unset($myrow['nohtml']);
		unset($myrow['nobreaks']);
		$this->set($myrow);
	  }
	}
  }
	
  function is_new() {
	if ($this->getVar('storyid') == 0) return true;
		return false;
	}
	
  function getform() {
	  global $xoopsModule,$op;
	  include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar('dirname')."/include/form.php";
  }
	
  function getListApproved() {
	  global $xoopsDB,$xoopsModule;
	  $sql="SELECT * FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))."_bak ORDER BY edited_time DESC";
		$result=$xoopsDB->query($sql);
		if ($result) {
		  echo '<table summary="border:0">';   
			echo '<tr><th width="1%">&nbsp;</th><th>'._INFO_OWNER.'</th><th>'._INFO_LINKNAME.'</th><th>'._INFO_LAST_EDITED.'</th><th width="1%">&nbsp;</th></tr>';
		  while ($row = $xoopsDB->fetcharray($result)) {
			  echo "<tr>";
				echo "<td width=\"1%\">";
				echo ($row['storyid']>0) ? "&nbsp;"._INFO_UPDATE."&nbsp;" : "&nbsp;"._INFO_NEW."&nbsp;";
				echo "</td>";
				$member_handler =& xoops_gethandler('member');
        $thisUser = $member_handler->getUser(intval($row['owner']));
				$owner = (is_object($thisUser) && ($thisUser->uname()!="")) ? $thisUser->uname() : _MI_INFO_GUEST;
				echo "<td width=\"32%\">".$owner."</td>";
				echo "<td width=\"32%\">".$row['title']."</td>";
				$last_time = ($row['edited_time']>0) ? date(_DATESTRING,$row['edited_time']) : "???";
				echo "<td width=\"32%\">".$last_time."</td>";
				echo "<td width=\"3%\" nowrap><a href='index.php?op=app_edit&id=".$row['bakid']."'><img src='../images/edit.gif' title='"._EDIT."'></a>";
	      echo " | <a href='index.php?op=app_delete&id=".$row['bakid']."'><img src='../images/delete.gif' title='"._DELETE."'></a></td>";
			  echo "</tr>";
			}
			echo "</table>";
		}
	}
	
  function getList($catid=0,$groupid=0) {
	global $xoopsModule,$xoopsDB,$_POST;
	require_once XOOPS_ROOT_PATH."/class/xoopstree.php";
	if ($catid==0) $this->setVar('catid',1);
	$sichtgroup =  (!empty($_POST['groupid'])) ? intval($_POST['groupid']) : 0;
	$myts =& MyTextSanitizer::getInstance();
	$info_tree = new XoopsTree($xoopsDB->prefix($xoopsModule->getVar('dirname')), "storyid", "parent_id");	
	$blocklist = new blockcategorie();
	$blocklist->load(intval($catid),$groupid);
	$form = new XoopsThemeForm('', $xoopsModule->getVar('dirname')."_form_delete", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	$form->setExtra('enctype="multipart/form-data"'); 
		
    $option_tray = new XoopsFormElementTray('','');
    $form->addElement(new XoopsFormHidden('op', 'blockcat_change'));
	$sql="SELECT catid,title FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." ORDER BY title ASC";
	$result=$xoopsDB->query($sql);
	$blist=array();
    if ($result) {
	  while($myrow = $xoopsDB->fetcharray($result)) {
	    $blist[$myrow['catid']] =  $myrow['title'];
	  }
	} 
	$block_select = new XoopsFormSelect(_INFO_HOMEPAGE, "cat",$blocklist->getVar('catid'));
	$block_select->addOptionArray($blist);
	$block_select->setextra('onchange="document.forms.'.$xoopsModule->getVar('dirname')."_form_delete".'.submit()"');
	$option_tray->addElement($block_select);
	$group_select = new XoopsFormSelectGroup(_INFO_AM_GROUP, 'groupid', true, $groupid, 1, false);
	$group_select->addOptionArray(array(0=>_ALL));
	$group_select->setextra('onchange="document.forms.'.$xoopsModule->getVar('dirname')."_form_delete".'.submit()"');
	$option_tray->addElement($group_select);
	$submit = new XoopsFormButton('', 'post', _SUBMIT, 'submit');
    $option_tray->addElement($submit);
	$form->addElement($option_tray);		
	$form->display();
   
	echo "<h4>"._INFO_HOMEPAGE." ==> ".$blocklist->getVar('title');
    if ($catid==1) echo " (default)";
	  $sql="SELECT m.storyid,m.homepage,m.title,c.title as cattitle FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." as m,".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_cat")." as c WHERE m.frontpage=1 AND c.catid=m.homepage ";
	  $result=$xoopsDB->query($sql);
	  if ($result) {
		$row = $xoopsDB->fetcharray($result);
		if (intval($row['storyid'])>0) {
		echo "<form action='index.php' method='post'>";
		echo "<br />"._AM_HP_SEITE." => [ ".$row['cattitle']." ] ".$row['title']."&nbsp;";
	    echo "<input type='hidden' name='cat' value='".$catid."'>";
		echo "<input type='hidden' name='op' value='deletehp'>";
		echo "&nbsp;<input type='submit' name='hpdelete' value='"._DELETE."'" ;
		echo "</form>";
	  } else {
		echo "<br />"._AM_HP_SEITE." => "._AM_HP_SEITE_NODEF;
	  }
	} else {
	   echo "<br />"._AM_HP_SEITE." => "._AM_HP_SEITE_NODEF;
	}
	echo "</h4>";
	echo "<form action='index.php' method='post'>";
	echo "<input type='hidden' name='hp' value='".$catid."'>";
	echo "<table border='1' cellpadding='0' cellspacing='1' width='100%' class='outer'>";
	echo "<tr class='even'>";
	echo "<td width=\"1%\" nowrap><b>"._INFO_FRONTPAGE."</b></td>";
	echo "<td width=\"1%\" nowrap><b>"._INFO_POSITION."</b></td><td><b>"._INFO_LINKNAME."</b></td>";
	echo "<td width=\"1%\" nowrap><b>"._INFO_LINKID."</b></td>";
	echo "<td width=\"1%\" nowrap><b>"._INFO_VISIBLE."</b></td>";
	if ($catid == 1)	echo "<td width=\"1%\" nowrap><b>"._INFO_SUBMENU."</b></td>";
	echo "<td width=\"1%\" nowrap><b>"._COMMENTS."</b></td>";
	echo "<td width=\"1%\" nowrap><b>"._INFO_ACTION."</b></td></tr>";
	
    $cAllList = $info_tree->getAllChild(0,"blockid");
	$mostra = array(0=>" ");
	foreach ($cAllList as $tc) {
	  if ($tc['homepage'] == $catid && $tc['storyid'] != $this->getVar('storyid')) {
	    $mostra[$tc['storyid']] = str_repeat ("--", count($info_tree->getAllParentId($tc['storyid']))) . $tc['title'];
	  }
	}
	$clist = $cAllList;
	foreach ($clist as $tcontent ) { 
	   if ($tcontent['homepage'] != $catid) continue;
	   if ($sichtgroup>0) {
	     $sg = explode(",",$tcontent['visible_group']);
	     if (!in_array($sichtgroup,$sg)) continue;
	   }
	   $menu = "<select name=\"parent_id[".$tcontent['storyid']."]\">";
	   foreach ($mostra as $key => $value) {
	     if ($key == $tcontent['storyid']) continue;
		 if ($key == $tcontent['parent_id']){
    	   $menu .= "<option value=\"".$key."\" selected='selected'>$value</option>";
		 } else {
    	   $menu .= "<option value=\"".$key."\">$value</option>";
    	 }    		
       }
       $menu .= '</select>';
       $title=$myts->makeTboxData4Show($tcontent['title'], 0, 0, 0);
	   
	   if ($tcontent['visible'] == '1') {
	     $check1 = "";
	     $check2 = "selected='selected'";
	   } else {
	     $check1 = "selected='selected'";
	     $check2 = "";
	   }

	   if ($tcontent['homepage'] == '1') {
	     $check3 = "checked='checked'";
	   } else {
	     $check3 = "";
	   }

	   if ($tcontent['nocomments'] == '1') {
	     $check4 = "selected='selected'";
	     $check5 = "";
	   } else {
	     $check4 = "";
	     $check5 = "selected='selected'";
	   }

	   if ($tcontent['submenu'] == '0') {
	     $check6 = "selected='selected'";
	     $check7 = "";
	   } else {
	     $check6 = "";
	     $check7 = "selected='selected'";
	   }
		 if ($tcontent['frontpage'] == '1') {
	     $check8 = "checked='checked'";
	   } else {
	     $check8 = "";
	   }
	   echo "<tr class='odd'>";
	   echo "<td width=\"1%\" nowrap>";
	   if ($tcontent['link']==0 || $tcontent['link']==1 || $tcontent['link']==4 || $tcontent['link']==5) {
		 echo "<input type='radio' name='fp[]' value='".$tcontent['storyid']." ".$check8."' />";
	   } else {
		 echo "&nbsp;";
	   }
		
	   echo "</td>";
	   echo "<td width=\"1%\" nowrap>$menu</td>";
	   echo "<td>";
	   if ($tcontent['st'] == 2) echo '<font color="red">'._MI_INFO_GESPERRT.'</font>&nbsp;';
	   echo str_repeat ("&nbsp;&nbsp;", count($info_tree->getAllParentId($tcontent['storyid']))); 
	   if ($tcontent['link'] == 3) { //kategorie
	     echo "<b>".$title."</b>";
	   } else { 
	     echo "<a href='".XOOPS_URL."/modules/".$xoopsModule->dirname()."/index.php?id=".$tcontent['storyid']."'>".$title."</a>";
	   }
	   echo "</td>";
	   if ($tcontent['parent_id'] == 0){
		   echo "<td width=\"1%\" nowrap><input type='hidden' name='id[]' value='".$tcontent['storyid']."' /><input type='text' name='blockid[".$tcontent['storyid']."]' size='5' maxlength='5' value='".$tcontent['blockid']."'/></td>";
	   }else{
		   echo "<td width=\"1%\" nowrap> <input type='hidden' name='id[]' value='".$tcontent['storyid']."' /><input type='text' name='blockid[".$tcontent['storyid']."]' size='5' maxlength='5' value='".$tcontent['blockid']."'/></td>";	  
	   }
	   echo "<td width=\"1%\" nowrap><select name='visible[".$tcontent['storyid']."]'><option value='0' ".$check1." />"._NO."</option><option value='1' ".$check2." />"._YES."</option></select></td>";
	   if ($catid == 1 && $tcontent['link'] != 3) {
	     echo "<td width=\"1%\" nowrap><select name='submenu[".$tcontent['storyid']."]'><option value='0' ".$check5." />"._NO."</option><option value='1' ".$check7." />"._YES."</option></select></td>";
	   } else {
		 if ($catid == 1) echo "<td width=\"1%\" nowrap>&nbsp;";
		 echo "<input type=\"hidden\" name=\"submenu[".$tcontent['storyid']."]\" value=\"".$tcontent['submenu']."\">";
		 if ($catid == 1) echo "</td>";
	   }
	   if ($tcontent['link'] == 0 || $tcontent['link'] == 4 || $tcontent['link'] == 5) {
	     echo "<td width=\"1%\" nowrap><select name='nocomments[".$tcontent['storyid']."]'><option value='1' ".$check4." />"._NO."</option><option value='0' ".$check5." />"._YES."</option></select></td>";
	   } else {
		 echo "<td width=\"1%\" nowrap>&nbsp;";
		 echo "<input type='hidden' name='nocomments[".$tcontent['storyid']."]' value='".$tcontent['nocomments']."'>";
		 echo "</td>";
	   }
	   echo "<td width=\"1%\" nowrap><a href='index.php?op=edit&id=".$tcontent['storyid']."'><img src='../images/edit.gif' title='"._EDIT."' alt='"._EDIT."'></a>";
	   echo " | <a href='index.php?op=delete&cat=$catid&id=".$tcontent['storyid']."'><img src='../images/delete.gif' title='"._DELETE."' alt='"._DELETE."'></a></td></tr>";
	   unset($tcontent);
   }   
	
	  echo "</table>";

	  echo "<br /><div align='center'>
    <input type='hidden' name='op' value='update' />
		<input type='hidden' name='cat' value='".$catid."' />
		<input type='submit' name='start' value="._SUBMIT." />
		<input type='button' name='newentry' value='"._INFO_ADDCONTENT."' onclick=\"location.href='index.php?op=edit&cat=$catid'\"/>
		</div>";
    echo "</form>";
	}
	
  function getData() {
	  if (isset($_POST)) {
		  $myts =& MyTextSanitizer::getInstance();
		  $rr=array();
			if (isset($_POST['title'])) $rr['title'] = $myts->stripSlashesGPC($_POST['title']); 
			if (isset($_POST['message'])) $rr['text'] = $myts->stripSlashesGPC($_POST['message']);	
			if (isset($_POST['homepage'])) $rr['homepage'] = intval($_POST['homepage']);
			if (isset($_POST['click'])) $rr['click'] = intval($_POST['click']);
			$rr['title_sicht'] = (isset($_POST['title_sicht'])) ? intval($_POST['title_sicht']) : 0;
			$rr['footer_sicht'] = (isset($_POST['footer_sicht'])) ? intval($_POST['footer_sicht']) : 0;
			if (isset($_POST['self'])) $rr['self'] = intval($_POST['self']);
			if (isset($_POST['storyid'])) $rr['storyid'] = intval($_POST['storyid']);
			if (isset($_POST['frontpage'])) $rr['frontpage'] = intval($_POST['frontpage']);
			if (isset($_POST['parent_id'])) $rr['parent_id'] = intval($_POST['parent_id']);
			if (isset($_POST['st'])) $rr['st'] = intval($_POST['st']);
			if (isset($_POST['bl_left'])) $rr['bl_left'] = intval($_POST['bl_left']);
			if (isset($_POST['bl_right'])) $rr['bl_right'] = intval($_POST['bl_right']);
			if (isset($_POST['blockid'])) $rr['blockid'] = intval($_POST['blockid']);
			$fr=unserialize($this->getVar('frame'));
			if (isset($_POST['iframe_height'])) {
			  if (intval($_POST['iframe_height'])>1000) $_POST['iframe_height']=999;
				if (intval($_POST['iframe_height'])<0) $_POST['iframe_height']=0;
			  $fr['height'] = intval($_POST['iframe_height']);
			}
			if (isset($_POST['iframe_border'])) {
			  if (intval($_POST['iframe_border'])>20) $_POST['iframe_border']=19;
				if (intval($_POST['iframe_border'])<0) $_POST['iframe_border']=0;
			  $fr['border'] = intval($_POST['iframe_border']);
			}
			if (isset($_POST['iframe_width'])) {
			  if (intval($_POST['iframe_width'])>100) $_POST['iframe_width']=100;
				if (intval($_POST['iframe_width'])<0) $_POST['iframe_width']=0;
			  $fr['width'] = intval($_POST['iframe_width']);
			}
			if (isset($_POST['iframe_align'])) {
			  $fr['align'] = trim($_POST['iframe_align']);
			}
			$rr['frame'] = serialize($fr);
			if (isset($_POST['visible'])) $rr['visible'] = intval($_POST['visible']);
			if (isset($_POST['dohtml'])) $rr['dohtml'] = intval($_POST['dohtml']);
			if (isset($_POST['nosmiley'])) $rr['nosmiley'] = intval($_POST['nosmiley']);
			if (isset($_POST['dobr'])) $rr['dobr'] = intval($_POST['dobr']);
			if (isset($_POST['nocomments'])) $rr['nocomments'] = intval($_POST['nocomments']);
			if (isset($_POST['submenu'])) $rr['submenu'] = intval($_POST['submenu']);
			if (isset($_POST['link'])) $rr['link'] = intval($_POST['link']);
			if (isset($_POST['tooltip'])) $rr['tooltip'] = strip_tags($_POST['tooltip']);
			if (isset($_POST['address'])) $rr['address'] = $myts->stripSlashesGPC($_POST['address']);
			if (isset($_POST['visible_group'])) $rr['visible_group'] = implode(",",$_POST['visible_group']);
			if (isset($_POST['owner'])) $rr['owner'] = intval($_POST['owner']);
			if (isset($_POST['bakid'])) $rr['bakid'] = intval($_POST['bakid']);
			$this->set($rr);
			unset($rr);
		  return true;
		}
		return false;
	}
	
	function insert() {
	  global $xoopsDB,$xoopsModule,$xoopsUser;
	  $myts =& MyTextSanitizer::getInstance();
	  $userid = ($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
	  if ($this->getVar('link') == 1) {
		$ma=str_replace(XOOPS_URL,"",$this->getVar('address'));
		$this->setVar('address',$ma);
	    if (strtolower(substr($this->getVar('address'),0,4)) == "http" || strtolower(substr($this->getVar('address'),0,3)) == "ftp") {
		  $this->seterrors(_INFO_ADMIN_URLINTERN);
		  return false;
		} 
	    if (substr($this->getVar('address'),0,1) != "/") {
		  $ma="/".$this->getVar('address');
		  $this->setVar('address',$ma);
		}
		$file=explode(".",basename($this->getVar('address')));
		if (isset($file[1]) && $file[1] == "") {
		  if (substr($this->getVar('address'),-1) != "/") {
			 $ma=$this->getVar('address')."/";
			 $this->setVar('address',$ma);
		  }
		}   
	  } elseif ($this->getVar('link') == 2 || $this->getVar('link') == 5) {
		if (strtolower(substr($this->getVar('address'),0,4)) == "http") {		
		}else {
		  if (strtolower(substr($this->getVar('address'),0,3)) == "ftp") {
		  } else {
		    $this->setErrors(_INFO_ADMIN_ERRURL);
		    return false;
		  }
		}
	  } elseif ($this->getVar('link') == 4) {
		if (substr($this->getVar('address'),0,1) != "/") {
		  $ma="/".$this->getVar('address');
		  $this->setVar('address',$ma);
		}
		if (!file_exists(XOOPS_ROOT_PATH.$this->getVar('address'))) {
		  $this->setErrors(_INFO_ADMIN_ERRDATEI);
		  return false;
		}
	  }
	  if ($this->is_new()) {
		  $sql="INSERT INTO ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." (parent_id,blockid,frontpage,title,text,visible,homepage,nohtml,nosmiley,nobreaks,nocomments,submenu,link,address,visible_group,edited_time,edited_user,click,self,frame,title_sicht,footer_sicht,tooltip,owner,st,bl_left,bl_right) VALUES (";
			$sql.= intval($this->getVar('parent_id'));
			$sql.= ",".intval($this->getVar('blockid'));
			$sql.= ",".intval($this->getVar('frontpage'));
			$sql.= ",'".$this->getVar('title','n')."'";
			$sql.= ",'".addslashes($this->getVar('text','n'))."'"; 
			$sql.= ",".intval($this->getVar('visible'));
			$sql.= ",".intval($this->getVar('homepage'));
			$sql.= ",".intval($this->getVar('dohtml'));
			$sql.= ",".intval($this->getVar('nosmiley'));
			$sql.= ",".intval($this->getVar('dobr'));
			$sql.= ",".intval($this->getVar('nocomments'));
			$sql.= ",".intval($this->getVar('submenu'));
			$sql.= ",".intval($this->getVar('link'));
			$sql.= ",'".$this->getVar('address')."'";
			$sql.= ",'".$this->getVar('visible_group')."'";
			if (is_object($xoopsUser)) {
			  $sql.= ",".time().",".$xoopsUser->getVar('uid');
			} else {
			  $sql.= ",".time().",0";
			}
			$sql.= ",".intval($this->getVar('click'));
			$sql.= ",".intval($this->getVar('self'));
			$sql.= ",'".addslashes($this->getVar('frame'))."'";
			$sql.= ",".intval($this->getVar('title_sicht'));
			$sql.= ",".intval($this->getVar('footer_sicht'));
			$sql.= ",'".trim($this->getVar('tooltip'))."'";
			$sql.= ",".intval($this->getVar('owner'));
			$sql.= ",".intval($this->getVar('st'));
			$sql.= ",".intval($this->getVar('bl_left'));
			$sql.= ",".intval($this->getVar('bl_right'));
			$sql.=")";
		} else {
		  $sql= "UPDATE ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." SET ";
			$sql.= "parent_id=".intval($this->getVar('parent_id'));
			$sql.= ",blockid=".intval($this->getVar('blockid'));
			$sql.= ",visible=".intval($this->getVar('frontpage'));
			$sql.= ",title='".$this->getVar('title','n')."'";
			$sql.= ",text='".addslashes($this->getVar('text','n'))."'";
			$sql.= ",visible=".intval($this->getVar('visible'));
			$sql.= ",homepage=".intval($this->getVar('homepage'));
			$sql.= ",nohtml=".intval($this->getVar('dohtml'));
			$sql.= ",nosmiley=".intval($this->getVar('nosmiley'));
			$sql.= ",nobreaks=".intval($this->getVar('dobr'));
			$sql.= ",nocomments=".intval($this->getVar('nocomments'));
			$sql.= ",link=".intval($this->getVar('link'));
			$sql.= ",submenu=".intval($this->getVar('submenu'));
			$sql.= ",address='".$this->getVar('address')."'";
			$sql.= ",visible_group='".$this->getVar('visible_group')."'";
			$sql.= ",edited_user=".$userid.", edited_time=".time();
			$sql.= ",click=".intval($this->getVar('click'));
			$sql.= ",self=".intval($this->getVar('self'));
			$sql.= ",frame='".addslashes($this->getVar('frame'))."'";
			$sql.= ",title_sicht=".intval($this->getVar('title_sicht'));
			$sql.= ",footer_sicht=".intval($this->getVar('footer_sicht'));
			$sql.= ",tooltip='".trim($this->getVar('tooltip'))."'";
			$sql.= ",owner=".intval($this->getVar('owner'))."";
			$sql.= ",st=".intval($this->getVar('st'))."";
			$sql.= ",bl_left=".intval($this->getVar('bl_left'))."";
			$sql.= ",bl_right=".intval($this->getVar('bl_right'))."";
			$sql.= " WHERE storyid=".intval($this->getVar('storyid'));
		}
		//echo $sql;
		//exit;
		$result=$xoopsDB->query($sql);
		if ($result) {
		  if (intval($this->getVar('bakid'))>0) {
			  $bakid = intval($this->getVar('bakid'));
				$sql = "DELETE FROM ".$xoopsDB->prefix($xoopsModule->getVar('dirname')."_bak")." WHERE bakid=".$bakid;
			  $result=$xoopsDB->queryF($sql);
			}
		  if ($this->is_new()) {			  
		    return true;
			} else {
			  $this->checkcat(intval($this->getVar('storyid')),intval($this->getVar('homepage')));
				return true;
			}
		} else {
		  $this->setErrors("MySQL-ERROR: <b>".mysql_error()."</b>");
		  return false;
		}
	}
	
	function checkcat($stid=0,$newblock=0) {
	  global $xoopsModule,$xoopsDB;
	  require_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->dirname()."/include/xoops.php";
      $cp = self_parrent($stid,$xoopsModule->dirname());
	  foreach ($cp as $key => $value) {
		  $sql = "UPDATE ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))." SET ";
			$sql.= " homepage=".intval($newblock);
		  $sql.= " WHERE storyid=".intval($value);
			$result=$xoopsDB->queryF($sql);
	  }
	  return true;
	}
	
	function backup() {
	  global $xoopsModule,$xoopsDB,$xoopsUser;
	    $sql="INSERT INTO ".$xoopsDB->prefix($xoopsModule->getVar('dirname'))."_bak (storyid,parent_id,blockid,frontpage,title,text,visible,homepage,nohtml,nosmiley,nobreaks,nocomments,submenu,link,address,visible_group,edited_time,edited_user,click,self,frame,title_sicht,footer_sicht,tooltip,owner,st,bl_left,bl_right) VALUES (";
		  $sql.= intval($this->getVar('storyid'));
			$sql.= ",".intval($this->getVar('parent_id'));
		  $sql.= ",".intval($this->getVar('blockid'));
			$sql.= ",".intval($this->getVar('frontpage'));
			$sql.= ",'".$this->getVar('title','n')."'";
			$sql.= ",'".addslashes($this->getVar('text','n'))."'"; 
			$sql.= ",".intval($this->getVar('visible'));
			$sql.= ",".intval($this->getVar('homepage'));
			$sql.= ",".intval($this->getVar('dohtml'));
			$sql.= ",".intval($this->getVar('nosmiley'));
			$sql.= ",".intval($this->getVar('dobr'));
			$sql.= ",".intval($this->getVar('nocomments'));
			$sql.= ",".intval($this->getVar('submenu'));
			$sql.= ",".intval($this->getVar('link'));
			$sql.= ",'".$this->getVar('address')."'";
			$sql.= ",'".$this->getVar('visible_group')."'";
			$sql.= ",".time()."";
			if ($xoopsUser) {
			  $sql.= ",".$xoopsUser->getVar('uid');
			} else {
			  $sql.= ",0";
			}
			$sql.= ",".intval($this->getVar('click'));
			$sql.= ",".intval($this->getVar('self'));
			$sql.= ",'".addslashes($this->getVar('frame'))."'";
			$sql.= ",".intval($this->getVar('title_sicht'));
			$sql.= ",".intval($this->getVar('footer_sicht'));
			$sql.= ",'".trim($this->getVar('tooltip'))."'";
			if ($xoopsUser) {
			  $sql.= ",".$xoopsUser->getVar('uid');
			} else {
			  $sql.= ",0";
			}
			$sql.= ",".intval($this->getVar('st'));
			$sql.= ",".intval($this->getVar('bl_left'));
			$sql.= ",".intval($this->getVar('bl_right'));
			$sql.=")";
			$result=$xoopsDB->query($sql);
		  if ($result) return true;
		  $this->setErrors("MySQL-ERROR: <b>".mysql_error()."</b>");
		  return false;
	}
	
	function getform_delete() {
	  global $xoopsModule,$xoopsDB;
		$catid = (isset($_GET['cat'])) ? intval($_GET['cat']) : ((isset($_POST['cat'])) ? intval($_POST['cat']) : 1);
	  $form = new XoopsThemeForm(_INFO_SETDELETE, $xoopsModule->getVar('dirname')."_form_delete", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	    $form->setExtra('enctype="multipart/form-data"');  
		$form->addElement(new XoopsFormHidden('id', $this->getVar('storyid')));	
		$form->addElement(new XoopsFormHidden('cat', $catid));	
		$form->addElement(new XoopsFormHidden('op', 'info_delete'));
		$form->addElement(new XoopsFormLabel('', sprintf(_INFO_INFODELETE_FRAGE,$this->getVar('title'))));
		$submit = new XoopsFormElementTray("", "");
	  $submit->addElement(new XoopsFormButton('', 'post', _YES, 'submit'));
		$submit->addElement(new XoopsFormButton('', 'post', _NO, 'submit'));
    $form->addElement($submit);
	  $form->display();
	}
	
	function getform_app_delete() {
	  global $xoopsModule,$xoopsDB,$id;
		$form = new XoopsThemeForm(_INFO_SETDELETE, $xoopsModule->getVar('dirname')."_form_delete", XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/admin/index.php');
	    $form->setExtra('enctype="multipart/form-data"');  
		$form->addElement(new XoopsFormHidden('id', $id));	
		$form->addElement(new XoopsFormHidden('op', 'app_info_delete'));
		$form->addElement(new XoopsFormLabel('', sprintf(_INFO_INFODELETE_FRAGE,$this->getVar('title'))));
		$submit = new XoopsFormElementTray("", "");
	  $submit->addElement(new XoopsFormButton('', 'post', _YES, 'submit'));
		$submit->addElement(new XoopsFormButton('', 'post', _NO, 'submit'));
    $form->addElement($submit);
	  $form->display();
	}
}
?>